package com.second.common.config;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * @program: clms-second
 * @description: Swagger接口文档配置类
 * @author: Lv Yongqi
 * @create: 2021-07-21 15:57
 **/
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    /**
     * 获取swagger2的实例对象docket
     * @return Docket
     */
    @Bean
    public Docket getDocket() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .groupName("second")
                .apiInfo(apiInfo())
                .select()
                //设置哪些请求路径生产接口文档,排除了/error路径下
                .paths(Predicates.not(PathSelectors.regex("/error.*")))
                .build();
        return docket;
    }

    private ApiInfo apiInfo() {
        Contact DEFAULT_CONTACT = new Contact("Second", "#", "#");
        ApiInfo apiInfo = new ApiInfo("汽车租赁后台管理系统API接口文档", "汽车租赁后台管理系统API接口文档",
                "2.0", "http://www.bing.com",
                DEFAULT_CONTACT, "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList<VendorExtension>());
        return apiInfo;
    }

}
